package com.cman777.springc.idempotence;

import com.cman777.springc.idempotence.storage.Storage;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.function.Supplier;

/**
 * @author chenzhicong
 * @time 2020/9/15 10:29
 */
public class IdempotenceClient {
    private Storage storage;
    @Autowired
    public IdempotenceClient(Storage cache) {
        this.storage = cache;
    }
    public  boolean saveIfAbsent(String idempotenceId, Supplier<ResultWrapper> supplier) {
        return storage.setIfAbsent(idempotenceId,supplier);
    }
    public <T extends Serializable> ResultWrapper<T>  getResult(String idempotenceId){
        return storage.getResult(idempotenceId);
    }



    public boolean delete(String idempotenceId) {
        return   storage.delete(idempotenceId);
    }


    public boolean exists(String idempotenceId){
        return  storage.exists(idempotenceId);
    }


}
